package JVM相关知识;

/**
 * @author coderFu
 * @create 2022/1/4
 * 线程死锁测试
 */
public class ThreadDeadLockTest {

    public static void main(String[] args) {
        // 制造死锁的情况
        for (int i = 0; i < 200; i++) {
            new Thread(new SynAddRunnable(1,2)).start();
            new Thread(new SynAddRunnable(2,1)).start();
        }
    }
}

class SynAddRunnable implements Runnable{

    int a  , b ;

    public SynAddRunnable(int a , int b){
        this.a = a;
        this.b = b;
    }

    @Override
    public void run() {
        //同时获取 a 和 b 的时候运行
        synchronized (Integer.valueOf(a)){
            synchronized (Integer.valueOf(b)){
                System.out.println(a+b);
            }
        }
    }
}
